package com.party.core.service.commune.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.commune.CMemberIntegralBalanceLogReadDao;
import com.party.core.dao.write.commune.CMemberIntegralBalanceLogWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.commune.CMemberIntegralBalanceLog;
import com.party.core.model.commune.IntegralItemInfoOutput;
import com.party.core.service.commune.ICMemberIntegralBalanceLogService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @ClassName TjMemberIntegralService
 * @Description
 * @Author shenliuhai
 * @Date 2020/4/15 17:19
 **/
@Service
public class CMemberIntegralBalanceLogService implements ICMemberIntegralBalanceLogService {


    @Autowired
    private CMemberIntegralBalanceLogReadDao consumReadDao;

    @Autowired
    private CMemberIntegralBalanceLogWriteDao consumWriteDao;


    @Override
    public String insert(CMemberIntegralBalanceLog t) {
        BaseModel.preInsert(t);
        boolean result = consumWriteDao.insert(t);
        if (result) {
            return t.getId();
        }
        return null;
    }

    @Override
    public boolean update(CMemberIntegralBalanceLog m) {
        m.setUpdateDate(new Date());
        return consumWriteDao.update(m);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return consumWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return consumWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return consumWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return consumWriteDao.batchDelete(ids);
    }

    @Override
    public CMemberIntegralBalanceLog get(String id) {
        return consumReadDao.get(id);
    }

    @Override
    public List<CMemberIntegralBalanceLog> listPage(CMemberIntegralBalanceLog CMemberIntegralBalanceLog, Page page) {
        return consumReadDao.listPage(CMemberIntegralBalanceLog,page);
    }

    @Override
    public List<CMemberIntegralBalanceLog> list(CMemberIntegralBalanceLog CMemberIntegralBalanceLog) {
        return consumReadDao.listPage(CMemberIntegralBalanceLog,null);
    }

    @Override
    public List<CMemberIntegralBalanceLog> batchList(Set<String> ids, CMemberIntegralBalanceLog CMemberIntegralBalanceLog, Page page) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.EMPTY_LIST;
        }
        return consumReadDao.batchList(ids,new HashMap<>(),page);
    }

    @Override
    public  List<Map<String,Object>> getIntegralSum(Map<String,Object> params) {
        return consumReadDao.getIntegralSum(params);
    }

    @Override
    public CMemberIntegralBalanceLog getBySourceId(String sourceId) {
        return consumReadDao.getBySourceId(sourceId);
    }

    @Override
    public List<IntegralItemInfoOutput> getCMemberIntegralBalanceLogs(Map<String, Object> params, Page page) {
        return consumReadDao.getCMemberIntegralBalanceLogs(params,page);
    }
}
